
#include "scr.h"

#ifdef MRC_MPC
#include "mpc.h"
#include "game.h"
#else
#include <base.h>
#include <exb.h>
#include <android.h>
#include <graphics.h>
#include <ex_math.h>
#endif

#ifdef MRC_MPC
void setTextSize(int f, int b) {
}

#endif

void scr_init(void) {
	// setscrsize(800,1200);
	setscrsize(240, 320);
	_SCRH = _SCRW * SCRH / SCRW;
	scr_ratio = SCRW * 1000 / 720;
}

static int d(int k) {
	return k * scr_ratio / 1000;
}

static int ud(int k) {
	return k * 1000 / scr_ratio;
}

int getd(int k) {
	return k * scr_ratio / 1000;
}

int getud(int k) {
	return k * 1000 / scr_ratio;
}

void drawCir1(int x, int y, int r, int32 c) {
	drawCir(d(x), d(y), d(r), c);
}

void drawRect1(int x, int y, int w, int h, int32 c) {
	drawRect(d(x), d(y), d(w), d(h), c);
}

static int font_flag = 1;

void setTextSize1(int f, int b) {
#ifdef MRC_MPC
	font_flag = b > 35 ? 1 : 0;
#else
	setTextSize(f, d(b));
#endif
}

static int32 dt_p1, dt_p2;

void textwh1(char *p, int u, uint16 font, int32 *w, int32 *h) {
#ifdef MRC_MPC
	skyfont_screenRect_t rect1;
	if (font_fail) {
		textwh(p, u, font, w, h);
	} else {
		rect1.x = 0;
		rect1.y = 0;
		rect1.w = _SCRW;
		rect1.h = _SCRH;
		mrc_skyfont_textWidthHeight((char *)c2u(p, &dt_p1, &dt_p2), 0, -1, 0, 0, rect1, 2, w, h);
	}
#else
	textwh(p, u, font, w, h);
#endif
	*w = ud(*w);
	*h = ud(*h);
}

void dtext1(char *tt, int16 x, int16 y, uint8 r, uint8 g, uint8 b, int u, uint16 f) {
#ifdef MRC_MPC
	mr_colourSt color1;
	skyfont_screenRect_t rect1;
	if (font_fail) {
		dtext(tt, d((int)x), d((int)y), r, g, b, u, f);
	} else if (font_flag == 0) {
		color1.r = r;
		color1.g = g;
		color1.b = b;
		rect1.x = d(x);
		rect1.y = d(y);
		rect1.w = _SCRW;
		rect1.h = _SCRH;
		mrc_skyfont_drawTextLeft((char *)c2u(tt, &dt_p1, &dt_p2), 0, -1, d(x), d(y), rect1, color1, 2);
	} else {
		dtext(tt, d((int)x), d((int)y), r, g, b, u, f);
	}
#else
	dtext(tt, d((int)x), d((int)y), r, g, b, u, f);
#endif
}

void dtextex1(char *pcText, int16 x, int16 y, rectst *rect, colorst *color, int flag, uint16 font) {
#ifdef MRC_MPC
	mr_colourSt color1;
	skyfont_screenRect_t rect1;
	colorst color2;
	rectst rect2;
	if (font_fail) {
		color2.r = color->r;
		color2.g = color->g;
		color2.b = color->b;
		rect2.x = d(rect->x);
		rect2.y = d(rect->y);
		rect2.w = d(rect->w);
		rect2.h = d(rect->h);
		dtextex(pcText, x, y, &rect2, &color2, flag, font);
	} else {
		color1.r = color->r;
		color1.g = color->g;
		color1.b = color->b;
		rect1.x = d(rect->x);
		rect1.y = d(rect->y);
		rect1.w = d(rect->w);
		rect1.h = d(rect->h);
		mrc_skyfont_drawTextLeft((char *)c2u(pcText, &dt_p1, &dt_p2), 0, -1, d(x), d(y), rect1, color1, 2);
	}
#else
	colorst color1;
	rectst rect1;
	color1.r = colorst->r;
	color1.g = colorst->g;
	color1.b = colorst->b;
	rect1.x = d(rect->x);
	rect1.y = d(rect->y);
	rect1.w = d(rect->w);
	rect1.h = d(rect->h);
	dtextex(pcText, x, y, rect1, color1, flag, font);
#endif
}

void drect1(int x, int y, int w, int h, int r, int g, int b) {
	drect(d(x), d(y), d(w), d(h), r, g, b);
}

int isPointCollRect1(int x, int y, int rectx, int recty, int rectw, int recth) {
	return isPointCollRect(x, y, rectx, recty, rectw, recth);
}

void toast1(char *text, int sp) {
	game_toast = strcpy(game_toast, text);
	game_toast_t = sp == 1 ? 1500 : 800;
}